﻿<UserControl x:Class="Lights.Controls.CollectionViewer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Lights.Controls"
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             Name="collectionViewer"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500">
    <UserControl.Resources>
        <CollectionViewSource x:Key="importSorted"  Source="{Binding ElementName=collectionViewer,Path=ItemsSource}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="Imported" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="150"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="121*"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <ListView x:Name="panel" 
            Grid.ColumnSpan="4"
            ItemsSource="{Binding Source={StaticResource importSorted}}"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ScrollViewer.IsDeferredScrollingEnabled="True">
            
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <local:VirtualizingWrapPanel Orientation="Horizontal" IsItemsHost="True" VirtualizingPanel.VirtualizationMode="Recycling" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid Width="{Binding ElementName=slider,Path=Value}" Height="{Binding ElementName=slider,Path=Value}" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="20"/>
                        </Grid.RowDefinitions>
                        <Image Margin="12" Source="{Binding Thumbnail}" >
                            <Image.Style>
                                <Style TargetType="{x:Type Image}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding AlreadyImported}" Value="True">
                                            <Setter Property="BitmapEffect" >
                                                <Setter.Value>
                                                    <BlurBitmapEffect Radius="10" KernelType="Box"/>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Image.Style>
                        </Image>
                        <TextBlock HorizontalAlignment="Center" Grid.Row="1" Text="{Binding Name}" Tag="{Binding Hashcode}" />
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        <TextBlock Grid.Row="1" Grid.Column="2" Text="Miniature:" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="3"/>
        <Slider x:Name="slider" Minimum="64" Maximum="256" Value="128" Grid.Row="1" Margin="3" Grid.Column="3"/>
    </Grid>
</UserControl>
